package com.dong.es.entity.dtocast.base;

import com.dong.es.entity.EsBaseDTO;
import com.dong.es.entity.EsViewDTO;
import com.dong.es.entity.dtocast.DTOCastMethod;
import com.dong.es.entity.searchparam.query.range.EsDataRangeQueryParam;

import java.util.Date;

/**
 * 使用示例：@DTOCastAnno(sort = 900, field = CsmLocDTO.QUERY_TIME, paramFields = {"startQueryTime", "endQueryTime"}, method = DTOCastRange.class),
 * {@code field = CsmLocDTO.QUERY_TIME} 对应 {@link #field}
 * {@code field = CsmLocDTO.QUERY_TIME} 对应 {@link #field}
 * {@code paramFields = {"startQueryTime", "endQueryTime"}} 对应 {@link #startTime} 和 {@link #endTime}
 *
 * @description: 时间范围 转换
 * @author: 陈瑞东
 * @create: 2022-06-21 14:57
 */
public class DTOCastRange extends DTOCastMethod {

    // 字段名
    private String field;
    // 开始时间
    private Date startTime;
    // 结束时间
    private Date endTime;

    @Override
    protected Integer sizeLimit() {
        return 3;
    }

    @Override
    protected Class[] typeLimit() {
        return new Class[] {String.class, Date.class, Date.class};
    }

    @Override
    protected void load(Object... args) {
        String field = args[0].toString();
        Date startTime = (Date) args[1];
        Date endTime = (Date) args[2];

        this.field = field;
        this.startTime = startTime;
        this.endTime = endTime;
    }

    @Override
    protected void doCast(EsViewDTO viewDTO, EsBaseDTO baseDTO) {
        new EsDataRangeQueryParam(field, startTime, endTime).addTo(baseDTO);
    }
}
